<template>
  <div>
    <h3>{{companyName}}</h3>
    <van-cell-group>
      <van-field label="上次处理人" :value="lastdealName" placeholder="暂无处理记录" readonly />
      <van-field type="textarea" label="上次处理意见" :value="lastdealOpinion" placeholder="暂无处理记录" readonly />
    </van-cell-group>
    <van-cell-group>
      <van-field readonly v-model="form.clrId" label="处理人" placeholder="请输入处理人" />
      <van-field type="textarea" autosize v-model="form.fk" label="处理意见" placeholder="请输入处理意见" />
    </van-cell-group>
    <br />
    <div class="btn">
      <van-button @click="submit" round type="info" size="large">提交</van-button>
      <van-button @click="end" class="endBtn" round type="primary" size="large">结束</van-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        clrId: "",
        fk: "",
        problemId: "",
        clzt: "",
      },
      lastdealName: "",
      lastdealOpinion: "",
    };
  },
  created() {
    this.form.problemId = this.$route.params.problemId;
    this.form.clrId = JSON.parse(sessionStorage.getItem("userData")).name;
    this.getLastDeal();
  },
  methods: {
    getLastDeal() {
      this.$api
        .disposalResults(
          { method: "post", type: "datagrid" },
          { problemId: this.$route.params.problemId }
        )
        .then((res) => {
          if (res.data.isSuccess) {
            this.lastdealName = res.data.data[0].clrId;
            this.lastdealOpinion = res.data.data[0].fk;
          }
        });
    },
    submit() {
      this.form.clzt = "1";
      this.$api
        .disposalResults({ method: "post", type: "save" }, this.form)
        .then((res) => {
          if (res.data.isSuccess) {
            this.$toast.success("提交成功");
            // this.form = {};
            // this.form.problemId = this.$route.params.problemId;
            // this.form.clrId = JSON.parse(sessionStorage.getItem("userData")).name;
            this.$router.go(-1)
            // this.getLastDeal();
          }
        });
    },
    end() {
      this.form.clzt = "2";
      this.$api
        .disposalResults({ method: "post", type: "save" }, this.form)
        .then((res) => {
          if (res.data.isSuccess) {
            this.$toast.success("结束成功");
            this.$router.go(-1)
            // this.form = {};
            // this.form.problemId = this.$route.params.problemId;
            // this.form.clrId = JSON.parse(sessionStorage.getItem("userData")).name;
            // this.getLastDeal();
          }
        });
    },
  },
  computed: {
    companyName() {
      return this.$route.params.title;
    },
    type() {
      return this.$route.params.type;
    },
  },
};
</script>

<style scoped lang="less">
h3 {
  text-align: center;
}
.endBtn {
  margin-top: 15px;
}
.btn {
  padding: 0 16px;
}
</style>
